package com.ruoyi.ipms_patent.controller;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.ipms_crm.entity.Customer;
import com.ruoyi.ipms_patent.entity.Patent;
import com.ruoyi.ipms_patent.service.PatentService;
import com.ruoyi.system.api.RemoteCustomerService;
import com.ruoyi.system.api.entity.Inventor;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/patent")
@RefreshScope    //开启支持nacos动态配置修改，默认是关闭，要开启
public class PatentController extends BaseController {

    @Resource
    private RemoteCustomerService remoteCustomerService;

    @GetMapping("/find/{id}")
    public AjaxResult getEmp(@PathVariable("id") Integer id) {
        if(id == 666){
            //return AjaxResult.success("【echo测试接口】专利测试接口：" + id);
            //TODO feign接口测试

            //测试触发fallbackFactory降级没生效。加了超时配置，1/0 超时都没触发。
            //int i = 1/0;

            //if(true){
            //    throw new RuntimeException("报错");
            //}

            return remoteCustomerService.findCustomer(id);
        }else {
            return AjaxResult.success("【echo测试接口】专利测试接口：" + id);
        }
    }


    @Resource
    private PatentService patentService;

    /*新增专利*/
    @PostMapping("/add")
    public AjaxResult addOne(@RequestBody Patent patent) {
        Patent result = patentService.addPatent(patent);
        return result != null ? AjaxResult.success("新增成功", result) : error("新增失败");
    }

    /*全部专利（客户id）*/
    @GetMapping("/find/{customerId}")
    public AjaxResult findListByCustomerId(@PathVariable("customerId") Integer customerId) {
        return AjaxResult.success("发明人列表",patentService.findPatentList(customerId));
    }


    /*定时器获取案件状态*/
    @GetMapping("/quartz/status")
    public AjaxResult getCaseOver() {
        return AjaxResult.success("成功" + DateUtils.getNowDate());
    }

    /* 修改专利材料地址 */
    @PostMapping("/updatePatent")
    public AjaxResult updatePatent(@RequestBody Patent patent){
        return toAjax(patentService.updatePatent(patent));
    }
}
